package com.imedway.ihe.dtz.xds.client;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import com.imedway.ihe.dd.properties.ItiAddressProps;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ClientBase {

    /**
     * 创建WebService服务
     *
     * @param portTypeClass   PortType
     * @param serviceWsdl     wsdl地址
     * @param itiAddressProps 配置
     * @return Service
     */
    public static <T> T buildWebService(Class<T> portTypeClass, String serviceWsdl, ItiAddressProps itiAddressProps) {
        URL wsdlUrl = null;
        try {
            wsdlUrl = new URL(serviceWsdl);
        } catch (MalformedURLException e) {
            log.error("创建WebService服务失败");
        }
        QName serviceName = new QName(itiAddressProps.getServiceNamespaceUri(), itiAddressProps.getServiceLocalPart());
        Service service = Service.create(wsdlUrl, serviceName);
        return service.getPort(portTypeClass);
    }
}
    
